<?php
require_once 'entity/Runner.php';
require_once 'entity/Team.php';
require_once 'tools/service/tools.php';
require_once 'tools/http/HTTP_REQUEST.php';
require_once 'tools/constant/Config.php';
include 'pages/header/correction_header.php';
$obj_utils=new DbUtils();
$tools=new Tool($dbUtils);
$obj_utils->connect();

if(HTTP_RESQUEST::exist("actionType") && HTTP_RESQUEST::post("actionType")=='runner'){
	
		$newDossard=HTTP_RESQUEST::post("newDossard");
		$oldDossard=HTTP_RESQUEST::post("oldDossard");
		$teamId=HTTP_RESQUEST::post("teamId");
		$obj_utils->updateDossard($oldDossard, $newDossard, $teamId);
		
		$runner1Id=HTTP_RESQUEST::post("runner1Id");
		$runner2Id=HTTP_RESQUEST::post("runner2Id");
		
		$nom1=HTTP_RESQUEST::post("nom1");
		$prenom1=HTTP_RESQUEST::post("prenom1");
		
		$nom2=HTTP_RESQUEST::post("nom2");
		$prenom2=HTTP_RESQUEST::post("prenom2");
		$sexe1=HTTP_RESQUEST::post("sexe1");
		$sexe2=HTTP_RESQUEST::post("sexe2");
		
		$obj_utils->updateRunner($nom1, $prenom1, $runner1Id,$sexe1);
		$obj_utils->updateRunner($nom2, $prenom2, $runner2Id,$sexe2);
		
		
}
$tabRunners=$obj_utils->getAllRaceTeams();


if($tabRunners!=0){
	?>
	<table class="principale">
		<tr><th colspan="5"><h2>Liste des courreurs du challenge</h2></th></tr>
		<tr>
			<th>Equipier 1</th>
			<th>Equipier 2</th>
			<th>Dossard</th>
			<th></th>
		</tr>
	
	<?php 
	for($i=0;$i<sizeof($tabRunners);$i++){?>
	<form action="./index.php?page=correction/correction_runner.php" method="post">
		<tr class="list">
			<td align="right">
				<div>Nom: <input type="text" value="<?php echo $tabRunners[$i]['nom1'];?>" name="nom1"/></div>
				<div>Prénom: <input type="text" value="<?php echo $tabRunners[$i]['prenom1']; ?>" name="prenom1" /></div>
				<div>
					<select name="sexe1">
						<option value="M" <?php echo $tabRunners[$i]['sexe1']=="M" ? "selected='selected'":"";?>>M</option>
						<option value="F" <?php echo $tabRunners[$i]['sexe1']=="F" ? "selected='selected'":"";?>>F</option>
					</select>
				</div>
				<input type="hidden" value="<?php echo $tabRunners[$i]['runner1Id'];?>" name="runner1Id"/>
			</td>
			<td align="right">
				<div>Nom: <input type="text" value="<?php echo $tabRunners[$i]['nom2'];?>" name="nom2"/></div>
				<div>Prénom: <input type="text" value="<?php echo $tabRunners[$i]['prenom2'];?>" name="prenom2"/></div>
				<input type="hidden" value="<?php echo $tabRunners[$i]['runner2Id'];?>" name="runner2Id"/>
				<div>
					<select name="sexe2">
						<option value="M" <?php echo $tabRunners[$i]['sexe2']=="M" ? "selected='selected'":"";?>>M</option>
						<option value="F" <?php echo $tabRunners[$i]['sexe2']=="F" ? "selected='selected'":"";?>>F</option>
					</select>
				</div>
			</td>
			<td class="listing" align="center">
				<input type="text" value="<?php echo($tabRunners[$i]['dossard']); ?>" name="newDossard"/>
				<input type="hidden" value="<?php echo($tabRunners[$i]['dossard']); ?>" name="oldDossard"/>
				<input type="hidden" value="<?php echo($tabRunners[$i]['id']); ?>" name="teamId"/>
			</td>
			<td class="listing" align="center">
				<input type="hidden" value="runner" name="actionType"/>
				<input type="submit" value="Mise à jour de L'équipe"/>
			</td>
		</tr>
	</form>
	<?php } ?>
	</table>
<?php
	
	}
	
	$obj_utils->close();
	
?>